package example.config;

import java.util.Collections;
import java.util.List;

public class PageConfig {
    public static List startPage(List list, Integer pageNum, Integer pageSize) {
        if (list == null) {
            return Collections.emptyList();
        }
        if (list.isEmpty()) {
            return Collections.emptyList();
        }
        //记录总数
        Integer count = list.size();

        //开始索引
        int fromIndex = (pageNum - 1) * pageSize;
        //结束索引
        int toIndex = pageNum * pageSize;
        if (fromIndex + 1 > count) {
            return Collections.emptyList();
        }
        if (pageNum * pageSize > count) {
            toIndex = count;
        }
        return list.subList(fromIndex, toIndex);
    }
}
